package com.zhongyu.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongyu.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {


   /* List<User> findAll(Wrapper wrapper);*/

    @Select("select t1.*,t2.id as role_id,t2.* from smbms_user t1\n" +
            "left  join smbms_role t2\n" +
            " on t1.user_role=t2.id ${ew.customSqlSegment}")
    @ResultMap("userRm")
    List<User> findAll(Page page , @Param("ew") Wrapper wrapper);
    @Select("select * from smbms_user where id=#{id}")
    List<User> selectById(Integer id);

    @Select("select username from smbms_user where id=#{userId}")
    String selectById1(Integer userId);
    @Select("select t1.*,t2.id as org_id,t2.* from smbms_user t1\n" +
            "left  join smbms_org t2\n" +
            " on t1.org_id=t2.id ${ew.customSqlSegment}")
    @ResultMap("userRm")
    List<User> findAll1(Page page , @Param("ew") Wrapper wrapper);

    /**
     * 库管员查询
     * @return
     */
    @Select("SELECT * FROM smbms_user WHERE user_role=6 OR user_role=1")
    List<User>findByKgUser();
    /**
     * 采购员查询
     * @return
     */
    @Select("SELECT * FROM smbms_user WHERE user_role=2 OR  user_role=1 or user_role=3")
    List<User>findByCgUser();
    /**
     * 销售员查询
     * @return
     */
    @Select("SELECT * FROM smbms_user WHERE user_role=4 OR  user_role=1 or user_role=5")
    List<User>findByXsUser();

    /**
     * 库存预警收件人
     * @return
     */
    @Select("SELECT * FROM smbms_user WHERE  user_role=1 OR user_role=3 OR user_role=2")
    List<User>findByGLUser();

@Update(" update smbms_user set user_role=#{roleId} where id=#{userId}")
    void update(@Param("userId") Integer userId, @Param("roleId") Integer roleId);
}
